package com.yikome.report.controller;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yikome.report.dto.AffilateReportDTO;
import com.yikome.report.request.AffilateReportRequest;
import com.yikome.report.service.ReportService;
import com.google.common.base.Preconditions;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/admin/report")
public class ReportController {

	@Autowired
	private ReportService reportService; 
	
	/**
	 * 投放维度报告
	 * 条件: 时间维度,汇率信息(TWD, NT$)
	 *输出: 投放人 | 单数 | SKU数 | 客单价
	 */
	@GetMapping("/affilate")
	public Collection<AffilateReportDTO> findAffilateReport(AffilateReportRequest affilateReportRequest){
		
		Preconditions.checkArgument(affilateReportRequest.getStartTime() != null, "时间参数不正确");
		Preconditions.checkArgument(affilateReportRequest.getEndTime() != null, "时间参数不正确");
		Preconditions.checkArgument(affilateReportRequest.getHk$() != null , "美元-港币汇率不存在");
		Preconditions.checkArgument(affilateReportRequest.getTwd$() != null , "美元-新台币汇率不存在");
		Preconditions.checkArgument(affilateReportRequest.getCny$() != null , "美元-人民币汇率不存在");
		
		return reportService.findAffilateReport(affilateReportRequest);
	}
	
	@GetMapping("/repeatRate")
	public BigDecimal findRepeatOrderrate(AffilateReportRequest affilateReportRequest){
		
		Preconditions.checkArgument(affilateReportRequest.getStartTime() != null, "时间参数不正确");
		Preconditions.checkArgument(affilateReportRequest.getEndTime() != null, "时间参数不正确");
		
		return reportService.findRepeatOrderrate(affilateReportRequest);
	}
}
